package com.gis.bigdata.spark02.core.framework.common

import com.gis.bigdata.spark02.core.framework.controller.WordCountController
import com.gis.bigdata.spark02.core.framework.util.EnvUtil
import org.apache.spark.{SparkConf, SparkContext}

/**
 * @author LnnuUser
 * @create 2022-10-07-下午9:54
 */
trait TApplication {

  def start(master:String = "local[*]", app:String = "Application")(op : => Unit) = {


    // Application
    // Spark框架
    //TODO 建立和Spark框架的连接
    val sparkConf = new SparkConf().setMaster(master).setAppName(app)
    val sc = new SparkContext(sparkConf)
    EnvUtil.put(sc)
    try{
      op
    }catch {
      case ex => println(ex.getMessage)
    }

    //TODO 关闭连接
    sc.stop()
    EnvUtil.clear()
  }

}
